#ifndef XSTDIO_H_
#define XSTDIO_H_
#include <cstdio>
#include "xstring.h"

std::FILE *safeFOpen (const char *filename,const char *modes);
std::FILE *safeTmpFile();
char* readLine(std::FILE* in,std::size_t* len);


std::size_t safeFRead(void *ptr, std::size_t size, std::size_t nmemb, std::FILE *stream);
std::size_t safeFWrite(const void *ptr, std::size_t size, std::size_t nmemb, std::FILE *stream);
int safeFSeek(std::FILE * stream, long int offset, int origin);
int safeFFlush(std::FILE * stream);

/***
 * LineReader
 */
class LineReader
    {
    protected:
   	char* buffer;
   	std::size_t buffer_capacity;
   	LineReader();
    public:
	virtual ~LineReader();
	virtual bool eof()=0;
	virtual int get()=0;
   	char* readLine(std::size_t* len);
    };

class FILELineReader:public LineReader
    {
    private:
	std::FILE* in;
    public:
	FILELineReader(std::FILE* in);
	virtual ~FILELineReader();
	virtual bool eof();
	virtual int get();
    };

class StringReader:public LineReader
    {
    private:
	const CharSequence* seq;
	std::size_t beg;
    public:
	StringReader(const CharSequence* seq);
	virtual ~StringReader();
	virtual bool eof();
	virtual int get();
    };


#endif

